package com.kingdee.eas.xr.helper;

/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.


import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.ParseException;

// Referenced classes of package com.kingdee.eas.ec.common:
//            EcConstant, EcArrayUtil

public class EcNumberHelper extends EcConstant
{

    public EcNumberHelper()
    {
    }

    public static BigDecimal toBigDecimal(Object obj)
    {
        BigDecimal bigDecimal = ZERO;
        if(null != obj)
            if(obj instanceof BigDecimal)
            {
                bigDecimal = (BigDecimal)obj;
            } else
            {
                NumberFormat numberFormat = NumberFormat.getInstance();
                String str = obj.toString().trim();
                Number number = null;
                try
                {
                    number = numberFormat.parse(str);
                }
                catch(ParseException e)
                {
                    e.printStackTrace();
                }
                if(null != number)
                    try
                    {
                        str = number.toString();
                        bigDecimal = new BigDecimal(str);
                    }
                    catch(Exception e) { }
            }
        return bigDecimal;
    }

    public static BigDecimal toBigDecimal(Object obj, int scale)
    {
        return toBigDecimal(obj).setScale(scale, 4);
    }

    public static BigDecimal add(Object dec1, Object dec2)
    {
        if(dec1 == null && dec2 == null)
            return null;
        else
            return toBigDecimal(dec1).add(toBigDecimal(dec2));
    }

    public static BigDecimal subtract(Object dec1, Object dec2)
    {
        if(dec1 == null && dec2 == null)
            return null;
        else
            return toBigDecimal(dec1).subtract(toBigDecimal(dec2));
    }

    /**
     * @deprecated Method divide is deprecated
     */

    public static BigDecimal divide(Object dec1, Object dec2)
    {
        return divide(dec1, dec2, 10, 4);
    }

    public static BigDecimal divide(Object dec1, Object dec2, int scale)
    {
        return divide(dec1, dec2, scale, 4);
    }

    public static BigDecimal divide(Object dec1, Object dec2, int scale, int roundingMode)
    {
        if(dec1 == null && dec2 == null)
            return null;
        if(toBigDecimal(dec2).signum() == 0)
            return null;
        else
            return toBigDecimal(dec1).divide(toBigDecimal(dec2), scale, roundingMode);
    }

    /**
     * @deprecated Method multiply is deprecated
     */

    public static BigDecimal multiply(Object dec1, Object dec2)
    {
        if(dec1 == null && dec2 == null)
            return null;
        else
            return toBigDecimal(dec1).multiply(toBigDecimal(dec2));
    }

    public static BigDecimal multiply(Object dec1, Object dec2, int scale)
    {
        if(dec1 == null || dec2 == null)
        {
            return null;
        } else
        {
            BigDecimal obj = toBigDecimal(dec1).multiply(toBigDecimal(dec2));
            return obj.setScale(scale, 4);
        }
    }

    public static boolean isPositiveBigDecimal(Object obj)
    {
        boolean isValid = false;
        if(toBigDecimal(obj).compareTo(ZERO) > 0)
            isValid = true;
        return isValid;
    }

    public static boolean isNullZero(BigDecimal bd)
    {
        boolean b = false;
        if(bd == null)
            b = true;
        if(bd != null && bd.compareTo(ZERO) == 0)
            b = true;
        return b;
    }

    public static int compareValue(Object obj1, Object obj2)
    {
        return toBigDecimal(obj1).compareTo(toBigDecimal(obj2));
    }

    public static boolean isGreaterThan(Object obj1, Object obj2)
    {
        return 1 == compareValue(obj1, obj2);
    }

    public static boolean isLessThan(Object obj1, Object obj2)
    {
        return -1 == compareValue(obj1, obj2);
    }

    public static boolean isEqual(Object obj1, Object obj2)
    {
        return 0 == compareValue(obj1, obj2);
    }

    public static BigDecimal add(Object objArr[])
    {
        BigDecimal rs = null;
        if(!EcArrayUtil.isAllNull(objArr))
        {
            rs = EcConstant.ZERO;
            int len = objArr.length;
            for(int i = 0; i < len; i++)
                rs = rs.add(toBigDecimal(objArr[i]));

        }
        return rs;
    }

    public static BigDecimal subtract(Object objArr[])
    {
        BigDecimal rs = null;
        if(!EcArrayUtil.isAllNull(objArr))
        {
            rs = toBigDecimal(objArr[0]);
            int len = objArr.length;
            for(int i = 1; i < len; i++)
                rs = rs.subtract(toBigDecimal(objArr[i]));

        }
        return rs;
    }

    public static BigDecimal multiply(Object objArr[])
    {
        BigDecimal rs = null;
        if(EcArrayUtil.isNotEmpty(objArr) && !EcArrayUtil.isSomeNull(objArr))
        {
            rs = toBigDecimal(objArr[0]);
            int len = objArr.length;
            for(int i = 1; i < len; i++)
                rs = rs.multiply(toBigDecimal(objArr[i]));

        }
        return rs;
    }
}


/*
	DECOMPILATION REPORT

	Decompiled from: F:\qs\lib\industry\ec_common-server.jar
	Total time: 0 ms
	Jad reported messages/errors:
	Exit status: 0
	Caught exceptions:
*/